<script setup>
// 新增车辆
import { ref,onMounted,watch} from 'vue'
import { message } from 'ant-design-vue'
import {getCostConfigurationManagerAPI,postCostConfigurationManagerAPI} from '@/services/configurationManager'
// 是否打开模态框-用于双向绑定
const props = defineProps(['open'])
const emit = defineEmits(['update:open', 'ok'])

// 表单组件实例
const formRef = ref()

// 表单字段
const formState = ref({
 trunkLine:undefined,
 branchLine:undefined,
 connectLine:undefined
})


//获取线路详情
const getCostList = async () => {
    const {data} = await getCostConfigurationManagerAPI()
    console.log(data)
    // formState.value = res.data
    data.forEach(ele=>{
      // console.log(ele)
      if(ele.transportLineType===1){
        formState.value.trunkLine=ele.cost
      }
      if(ele.transportLineType===2){
        formState.value.branchLine=ele.cost
      }
      if(ele.transportLineType===3){
        formState.value.connectLine=ele.cost
      }
    })
}

onMounted(()=>{
getCostList()
})

//确定
const  onOk = async ()=>{
  const obj=[
    {"cost": formState.value.trunkLine, "transportLineType": 1},
    {"cost": formState.value.branchLine, "transportLineType": 2},
    {"cost": formState.value.connectLine, "transportLineType": 3},
  ]
  console.log(obj)
  emit('ok',obj)

}


</script>

<template>
  <a-modal
    :open="open"
    :title="'成本设置'"
    @ok="onOk"
     @update:open="emit('update:open', $event)"
  >
    <a-form ref="formRef" :model="formState" :labelCol="{ span: 5 }">
      <a-form-item label="线路类型"  
       >
       每公里平均成本(元)
      </a-form-item>
      <a-form-item label="干线" name="trunkLine" required>
        <a-input v-model:value="formState.trunkLine"   />
      </a-form-item>
      <a-form-item label="支线" name="branchLine" required>
        <a-input v-model:value="formState.branchLine"   />
      </a-form-item>
      <a-form-item label="接驳" name="connectLine" required>
        <a-input v-model:value="formState.connectLine"   />
      </a-form-item>
     
    </a-form>
  </a-modal>
</template>
